package com.mmy.dao.car;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.car.TCarOrg;

public interface TCarOrgRepository extends JpaRepository<TCarOrg, Integer> {

	/*
	 * 获取最大值id
	 */
	@Query(value = "select MAX(iOrgID) from tCarOrg", nativeQuery = true)
	Object getMaxOrgID();

	/*
	 * 根据name查找
	 */
	@Query(value = "select *  from tCarOrg where cOrgName like %:strOrgName%", nativeQuery = true)
	List<TCarOrg> findByOrgName(@Param("strOrgName") String strOrgName);

	/*
	 * 根据id删除
	 */
	@Transactional
	@Modifying
	@Query(value = "delete from tCarOrg where tCarOrg.iOrgID in (:lstOrgID)", nativeQuery = true)
	void delCarOrg(@Param("lstOrgID") List<Integer> lstOrgID);

	/*
	 * 根据id查找
	 */
	@Query(value = "select *  from tCarOrg where iOrgID = :iOrgID", nativeQuery = true)
	TCarOrg findByOrgID(@Param("iOrgID") int iOrgID);


	/*
	 * 新建id
	 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tCarOrg(iOrgID, cOrgName, cContact, cMobile, cTel, cFax, cAddress, iNumber, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5, dCreateDate) VALUES (:orgID, NULL, NULL, NULL, NULL, NULL, NULL, 2, NULL, NULL, NULL, '', NULL, NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(@Param("orgID") int orgID);

}
